package cn.wolfcode;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MyGenerator {

    public static void main(String[] args) {
        //AutoGenerator mp的代码生成器对象
        AutoGenerator autoGenerator = new AutoGenerator();
        //配置代码生成器
//        autoGenerator.setGlobalConfig() 全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        //配置输出路径，不包含包路径
        String path = System.getProperty("user.dir");
        globalConfig.setOutputDir(path+"/src/main/java");
        globalConfig.setIdType(IdType.AUTO);
        globalConfig.setControllerName("%sController");
        globalConfig.setMapperName("%sMapper");
        globalConfig.setServiceName("I%sService");
        globalConfig.setServiceImplName("%sServiceImpl");
        globalConfig.setAuthor("yunan");
        globalConfig.setBaseResultMap(true);
        globalConfig.setBaseColumnList(true);
        autoGenerator.setGlobalConfig(globalConfig);
//        autoGenerator.setStrategy() 策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
        autoGenerator.setStrategy(strategyConfig);
//        autoGenerator.setDataSource() 数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
        dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/testmp42");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("123456");
        autoGenerator.setDataSource(dataSourceConfig);
//        autoGenerator.setPackageInfo() 包配置\
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("cn.wolfcode");
        autoGenerator.setPackageInfo(packageConfig);

        //执行生成器
        autoGenerator.execute();

    }

}
